/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.himilco.ocana.workflow.core.dao;

import com.himilco.ocana.workflow.core.dao.entities.Incident;
import com.himilco.ocana.workflow.core.dao.entities.Ticket;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;

/**
 *
 * @author oussema TOUKEBRI
 */
public class AdminDAL {

    private EntityManager entityManager;

    public AdminDAL(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    public List<Ticket> findAll() {
//        initDB();
        javax.persistence.Query query = entityManager.createQuery("SELECT i FROM db_ocana_ticket i where status='OPEN'");
        List<Ticket> results = query.getResultList();
        System.out.println("Nbr Tickets DAL Operator: " + results.size());
        return results;
    }

    public void initDB() {
        Incident incident1 = new Incident("IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT");
        entityManager.persist(incident1);
        Ticket ticket1 = new Ticket();
        ticket1.setStartTime(new Date());
        ticket1.setStatus("OPEN");
        ticket1.setIncident(incident1);
    }

    public EntityManager getEntityManager() {
        return entityManager;
    }
}
